import {URL} from "node:url"
import path from "node:path"

// 获取当前文件的完整路径
const __filename = new URL('',import.meta.url).pathname


const basename = path.basename(__filename)
const dirname = path.dirname(__filename)
const extname = path.extname(__filename)

console.log(basename); // path_demo.js
console.log(dirname); // /D:/gitee/Tutorial/JavaScriptTutorial/node/lesson01/core_path
console.log(extname); // .js


// 创建一个Path对象
console.log(path.parse(__filename))
/**
{
  root: '/',
  dir: '/D:/gitee/Tutorial/JavaScriptTutorial/node/lesson01/core_path',
  base: 'path_demo.js',
  ext: '.js',
  name: 'path_demo'
}
 */
const __dirname = new URL('.',import.meta.url).pathname
console.log(path.join(__dirname,"test","note.txt"));